<template>
  <div class="app-container">
    <el-form
      class="searchform"
      :model="queryParams"
      ref="queryParams"
      size="small"
      inline
    >
      <el-form-item label="仪器名称或编号" label-width="110px">
        <el-input
          v-model="queryParams.nameOrNumber"
          placeholder="请输入"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="受检单位">
        <entrustSelect :eid.sync="queryParams.organizationId"></entrustSelect>
      </el-form-item>
      <el-form-item label="使用时间">
        <el-date-picker
          style="width: 300px"
          v-model="createTime"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始"
          end-placeholder="结束"
          align="right"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label-width="20px">
        <el-button type="primary" icon="el-icon-search" @click="getList()"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="reset()">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-wrapper">
      <use-record-list
        ref="useRecordList"
        :queryParams="queryParams"
        :showPrintBtn="true"
      ></use-record-list>
    </div>
  </div>
</template>

<script>
import entrustSelect from "@/components/select/src/entrustSelect";
import useRecordList from "./components/useRecordList.vue";
export default {
  name: "useRecord",
  components: { entrustSelect, useRecordList },
  data() {
    return {
      queryParams: {},
      queryParamsCache: {
        createTimeEnd: null,
        createTimeStart: null,
      },
    };
  },
  mounted() {
    this.init();
  },
  computed: {
    createTime: {
      get() {
        return this.queryParams.createTimeStart &&
          this.queryParams.createTimeEnd
          ? [
              new Date(this.queryParams.createTimeStart),
              new Date(this.queryParams.createTimeEnd),
            ]
          : null;
      },
      set(val) {
        this.queryParams.createTimeStart = val ? this.parseTime(val[0]) : null;
        this.queryParams.createTimeEnd = val ? this.parseTime(val[1]) : null;
      },
    },
  },
  methods: {
    changeState(row, state) {
      updateState({
        id: row.id,
        usageTime: state.replace("use", "").toUpperCase(),
        usageState: row[state],
      });
    },
    init() {
      this.reset();
    },
    reset() {
      this.queryParams = JSON.parse(JSON.stringify(this.queryParamsCache));
      this.$refs.useRecordList.reset();
      this.getList();
    },
    getList() {
      this.$nextTick(() => {
        this.$refs.useRecordList.getList();
      });
    },
  },
};
</script>

<style></style>
